<?php
namespace Zxf5115\Laravel\Resource\Models\Common;

use Zxf5115\Laravel\Kernel\Models\Base;
use Illuminate\Database\Eloquent\Builder;

/**
 * @author zhangxiaofei [<1326336909@qq.com>]
 * @dateTime 2025-09-10
 *
 * 资源模型类
 */
class Resource extends Base
{
  /**
   * 数据库表名
   */
  public $table = "system_resource";

  /**
   * 批量赋值允许的字段
   */
  public $fillable = [
    'id',
    'organization_id',
    'name',
    'size',
    'extension',
    'url',
    'hash',
  ];

  /**
   * 需要隐藏的字段
   */
  public $hidden = [
    'update_time'
  ];

  /**
   * 只查询hash值的作用域
   *
   * @param Builder $query 查询对象
   * @param string $hash hash值
   * @return Builder 查询对象
   */
  public function scopeByHash(Builder $query, string $hash) : Builder
  {
    return $query->where(['hash' => $hash, 'status' => 1]);
  }
}
